package acwing.栈;

import java.util.Scanner;

/**
 * @description:
 * @author: qian
 * @createDate: 2021/11/12
 */
public class Stack {

    static int N = 100010;
    static int[] s = new int [N];
    static int top;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            while (top != 0 && s[top] >= x) top--;
            if (top != 0) System.out.println(s[top] + " ");
            else System.out.println(-1 + " ");

            s[++top] = x;
        }
    }
}
